Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to see if pre_model_hook works for tests around snowflake_warehouse #1070

Merged
merged 13 commits into from
Jun 14, 2024

Conversation

McKnight-42
Copy link
Contributor

@McKnight-42 McKnight-42 commented Jun 4, 2024

resolves #1059
docs dbt-labs/docs.getdbt.com/#

Problem

We want to be able to correctly handle arbitrary configs in tests correctly, for models this is currently done with pre/post_model_hook and for snowflake this is mainly for swapping snowflake_wareshouse values, currently we don't actually recognize this config in during tests. by adding updating dbt-core methods we have opened up the ability to pass these into tests correctly but must make specific modifications in the adapters themselves.

asks:

  1. update for logging
  2. add tests

Solution

we can use AdapterLogger to add loggger.info as we need in the model_hook methods

add a new tests to handle scenarios i.e we update snowflake_warehouse to a invalid warehouse.

blocked by:
dbt-labs/dbt-core#10258

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX

@McKnight-42 McKnight-42 added the Skip Changelog Skips GHA to check for changelog file label Jun 4, 2024
@McKnight-42 McKnight-42 self-assigned this Jun 4, 2024
@cla-bot cla-bot bot added the cla:yes label Jun 4, 2024
@McKnight-42
Copy link
Contributor Author

running test without the expect_pass shows this in logs

use warehouse DBT_TEST_DOES_NOT_EXIST
�[0m11:01:25.737689 [debug] [Thread-22 ]: Snowflake adapter: Snowflake query id: 01b4cf21-0804-bc1d-000d-3783363da962
�[0m11:01:25.739334 [debug] [Thread-22 ]: Snowflake adapter: Snowflake error: 002043 (02000): SQL compilation error:
Object does not exist, or operation cannot be performed.

Comment on lines 105 to 111
logger.info("Running pre_model_hook:")
logger.info(f"Default warehouse: {default_warehouse}, Selected warehouse: {warehouse}")
if warehouse == default_warehouse or warehouse is None:
return None
previous = self._get_warehouse()
self._use_warehouse(warehouse)
logger.info(f"Changed wareho use from {previous} to {warehouse}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to put these logs behind condition of warehouses being different?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@McKnight-42 I don't think we should add any new logging here. The actual queries being run (select current_warehouse() as warehouse + use warehouse different_warehouse) are already appearing in the logs.

Comment on lines 105 to 111
logger.info("Running pre_model_hook:")
logger.info(f"Default warehouse: {default_warehouse}, Selected warehouse: {warehouse}")
if warehouse == default_warehouse or warehouse is None:
return None
previous = self._get_warehouse()
self._use_warehouse(warehouse)
logger.info(f"Changed wareho use from {previous} to {warehouse}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@McKnight-42 I don't think we should add any new logging here. The actual queries being run (select current_warehouse() as warehouse + use warehouse different_warehouse) are already appearing in the logs.

"config-version": 2,
"models": {
"test": {
"snowflake_warehouse": "DBT_TEST_DOES_NOT_EXIST",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, nicely done - we should expect the dbt test to try using a Snowflake warehouse that doesn't exist (use warehouse DBT_TEST_DOES_NOT_EXIST), where previously it wouldn't, and so it should fail with Object does not exist, or operation cannot be performed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

went ahead and also added a assert to catch if that error message stops showing up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the sake of completeness, can we add a positive test case that uses this config option, just to make sure it's setting it? The error message we're getting in the negative test case is pretty general.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a new test

@McKnight-42 McKnight-42 marked this pull request as ready for review June 6, 2024 15:58
@McKnight-42 McKnight-42 requested a review from a team as a code owner June 6, 2024 15:58
@McKnight-42 McKnight-42 requested a review from jtcohen6 June 6, 2024 16:00
dev-requirements.txt Outdated Show resolved Hide resolved
@McKnight-42 McKnight-42 changed the title [Feature] update pre/post_model_hooks for tests [Feature] Add tests to see if pre_model_hook works for tests around snowflake_warehouse Jun 11, 2024
Copy link
Contributor

@ChenyuLInx ChenyuLInx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit otherwise LGTM



class TestValidConfigWarehouse:
@pytest.fixture(scope="class")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you just need to define this and the other model in outside of all classes once.

@ChenyuLInx
Copy link
Contributor

This is just a test I don't think it is a feature.

@McKnight-42
Copy link
Contributor Author

This is just a test I don't think it is a feature.

currently labeled as such because it ties with the core prs dbt-labs/dbt-core#10258 and dbt-labs/dbt-core#10245 but yeah could possibly just be a under the hood update.

@McKnight-42 McKnight-42 changed the title [Feature] Add tests to see if pre_model_hook works for tests around snowflake_warehouse Add tests to see if pre_model_hook works for tests around snowflake_warehouse Jun 14, 2024
@McKnight-42 McKnight-42 merged commit a886ac1 into main Jun 14, 2024
18 checks passed
@McKnight-42 McKnight-42 deleted the mcknight/1059 branch June 14, 2024 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes Skip Changelog Skips GHA to check for changelog file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] add functional test to cover new cover new custom config for tests.
5 participants